import java.util.HashMap;
import java.util.Map;

/**
 * @author jianshan@byai.com
 * @date 2021/2/25 2:06 PM
 * describe:
 */
public class MessageScript {


    public static void main(String[] args) {
        Map<String,Object> params = new HashMap<>();
        params.put("开户行卡号后四位","332505199411255612");
        params.put("开户行名称","杭州XX行");
        params.put("开户行地址","杭州上城区XX路");
        System.out.println(processTemplate(params));
    }



    private static String processTemplat2(Map<String, Object> params){
//        String templateMessage = "您尾号${开户行卡号后四位}的账户开户行是${开户行名称}，地址是${开户行地址}";
//        try {
//            Template template = new Template("strTpl", templateMessage, new Configuration(Configuration.VERSION_2_3_28));
//            StringWriter result = new StringWriter();
//            template.process(params, result);
//            return result.toString();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return null;
    }


    private static String processTemplate(Map<String, Object> args){
//        Map<String,Object> params = args;
//        if (params == null || params.keySet().isEmpty()) {
//            params = new HashMap<>();
//        }
//        String templateMessage = "您尾号${开户行卡号后四位}的账户开户行是${开户行名称}，地址是${开户行地址}";
//        Matcher matcher = Pattern.compile("[$]\\{.*?\\}").matcher(templateMessage);
//        StringBuffer sb = new StringBuffer();
//        while (matcher.find()) {
//            String group = matcher.group();
//            if (group == null || group.trim().length() <= 0) {
//                continue;
//            }
//            String variableName = group.substring(2, group.length() - 1);
//            if (variableName.trim().length() <= 0) {
//                continue;
//            }
//            Object variableValue = params.get(variableName);
//            matcher.appendReplacement(sb, variableValue==null ? "" : variableValue.toString());
//        }
//        matcher.appendTail(sb);
//        return sb.toString();
        return null;
    }


    private static String processTemplate(){
        String cardNumber = "卡号";
        String accountBankName= "开户行名称";
        String accountBankAdrress = "开户行地址";
        if (cardNumber == null || accountBankName == null || accountBankAdrress == null) {
            return null;
        }
        int length = cardNumber.length();
        if (length < 5) {
            return null;
        }
        cardNumber = cardNumber.substring(length-4,length);
        String templateMessage = "您尾号"+cardNumber+"的账户开户行是"+accountBankName+"，地址是"+accountBankAdrress;
        return templateMessage;

    }
}
